package com.hlhj.carview.aty

import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.text.Layout
import android.view.LayoutInflater
import android.view.View
import com.hlhj.carview.BaseAty
import com.hlhj.carview.Iview.EquipmentDetailView
import com.hlhj.carview.R
import com.hlhj.carview.adapter.EquipmentDetailListAdp
import com.hlhj.carview.bean.EquipmentDetailBean
import com.hlhj.carview.presenter.EquipmentDetailPresenter
import com.hlhj.carview.presenter.EquipmentPresenter
import kotlinx.android.synthetic.main.aty_equipment_detail.*
import kotlinx.android.synthetic.main.lo_pubhead.*

/**
 * Created by Never Fear   on 2018\12\21 0021.
Never More....
 */
class EquipmentDetailAty :BaseAty<EquipmentDetailView, EquipmentDetailPresenter>(), EquipmentDetailView {
    private var adp:EquipmentDetailListAdp?=null
    private val datas=ArrayList<EquipmentDetailBean.InfoBean.RepairBean>()
    private var emptyView:View?=null
    private var id =0
    override fun setDetail(equipmentDetailBean: EquipmentDetailBean) {
        itemNum.text="设备编号：${equipmentDetailBean.info.device_sn}"
        itemType.text="型号：${equipmentDetailBean.info.version}"
        itemColor.text="颜色：${equipmentDetailBean.info.color}"
        itemSys.text="系统：${equipmentDetailBean.info.system}"
        itemPlate.text="${equipmentDetailBean.info.car_number}"

        equipmentDetailBean.info.repair?.let {
            datas.addAll(it)
            adp?.notifyDataSetChanged()
        }
    }

    override fun initView() {
        id=intent.getIntExtra("id",0)
        emptyView=LayoutInflater.from(this).inflate(R.layout.equipment_detail_empty,null)

        adp= EquipmentDetailListAdp(datas)
        statusList.adapter=adp
        statusList.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)

        adp?.setEmptyView(emptyView)

    }

    override fun logicStart() {
        presenter?.getDetail(intent.getIntExtra("id",0),this)
    }

    override fun setListener() {
        emptyView?.findViewById<View>(R.id.btGo)?.setOnClickListener {
            val intent = Intent(this, AddEquipmentAty::class.java)
            intent.putExtra("did",id)
            startActivityForResult(intent,1)
        }
        btExit.setOnClickListener {
            setResult(-1)
            finish()
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode!=-1)return
        if (requestCode==1){
            presenter?.getDetail(intent.getIntExtra("id",0),this)

        }
    }
    override fun bindView(): EquipmentDetailView {
        return this
    }

    override fun createPresenter(): EquipmentDetailPresenter {
        return EquipmentDetailPresenter()
    }

    override fun getContentID(): Int {
        return R.layout.aty_equipment_detail
    }
}